package hu.radai.jsfportal.bean;

import java.util.HashMap;
import java.util.Map;

import hu.radai.jsfportal.log.LogManagerUtil;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

/**
 * @author Radai Tamas
 */
@ManagedBean(name = "loginBean")
@ViewScoped
public class LoginBean implements BaseBean {

	/**
	 * 
	 */
	private static final long serialVersionUID = -5254891438991766958L;

	private String loginName;

	private String loginPassword;

	private Integer loginNameMinLength;

	private Integer loginPasswordMinLength;

	private String loginPasswordRegex;

	private Map<String, String> menu;

	/**
	 * 
	 */
	public LoginBean() {
		this.loginName = null;
		this.loginPassword = null;
		this.loginNameMinLength = null;
		this.loginPasswordMinLength = null;
		this.loginPasswordRegex = null;
		this.menu = null;
	}

	@PostConstruct
	public void init() {
		this.loginName = "";
		this.loginPassword = "";
		this.loginNameMinLength = LoginConstants.MIN_LENGTH_USER_NAME;
		this.loginPasswordMinLength = LoginConstants.MIN_LENGTH_USER_PASSWORD;
		this.loginPasswordRegex = LoginConstants.USER_PASSWORD_REGEX;
		this.menu = new HashMap<String, String>(0);
		this.menu.put("testMenu1Key", "testMenu1Value");
		this.menu.put("testMenu2Key", "testMenu2Value");
		this.menu.put("testMenu3Key", "testMenu3Value");
		LogManagerUtil.debug(this.getClass(), "init done");
	}

	@PreDestroy
	public void destroy() {
		this.loginName = null;
		this.loginPassword = null;
		this.loginNameMinLength = null;
		this.loginPasswordMinLength = null;
		this.loginPasswordRegex = null;
		this.menu = null;
		LogManagerUtil.debug(this.getClass(), "destroy done");
	}

	/**
	 * @return the loginName
	 */
	public String getLoginName() {
		return this.loginName;
	}

	/**
	 * @param loginName
	 *            the loginName to set
	 */
	public void setLoginName(final String loginName) {
		this.loginName = loginName;
	}

	/**
	 * @return the loginPassword
	 */
	public String getLoginPassword() {
		return this.loginPassword;
	}

	/**
	 * @param loginPassword
	 *            the loginPassword to set
	 */
	public void setLoginPassword(final String loginPassword) {
		this.loginPassword = loginPassword;
	}

	/**
	 * @return the loginNameMinLength
	 */
	public Integer getLoginNameMinLength() {
		return this.loginNameMinLength;
	}

	/**
	 * @return the loginPasswordMinLength
	 */
	public Integer getLoginPasswordMinLength() {
		return this.loginPasswordMinLength;
	}

	/**
	 * @return the loginPasswordRegex
	 */
	public String getLoginPasswordRegex() {
		return this.loginPasswordRegex;
	}

	/** 
	 * @return the menu
	 */
	public Map<String, String> getMenu() {
		this.menu = new HashMap<String, String>(0);
		this.menu.put("testMenu1Key", "testMenu1Value");
		this.menu.put("testMenu2Key", "testMenu2Value");
		this.menu.put("testMenu3Key", "testMenu3Value");
		return menu;
	}
	
	/**
	 * @param menu
	 *            themenu to set
	 */
	public void setMenu(Map<String, String> menu) {
		this.menu = menu;
	}
}
